#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'dong'

from peewee import *
from datetime import date


# 新建数据库 db
db = SqliteDatabase('people.db')


class Person(Model):
    name = CharField()
    birthday = DateField()
    is_relative = BooleanField()

    class Meta:
        database = db


class Pet(Model):
    owner = ForeignKeyField(Person, related_name='pets')
    name = CharField()
    animal_type = CharField()

    class Meta:
        database = db


db.connect()

# db.create_tables([Person, Pet])

uncle_bob = Person(name='Bob', birthday=date(1967, 1, 28), is_relative=True)
uncle_bob.save()

grandma = Person.create(name='Grandma', birthday=date(1935, 3, 1), is_relative=True)
herb = Person.create(name='Herb', birthday=date(1950, 5, 1), is_relative=False)

grandma.name = 'Marry'
grandma.save()

bob_kitty = Pet.create(owner=uncle_bob, name='Kitty', animal_type='cat')
herb_fido = Pet.create(owner=herb, name='Fido', animal_type='dog')
herb_mittens = Pet.create(owner=herb, name='Mittens', animal_type='cat')
herb_mittens_jr = Pet.create(owner=herb, name='Mittens Jr', animal_type='cat')
